﻿using AutoMapper;
using MediatR;
using Traceability.App.Api.Read.Application.Command.Kill;
using Traceability.App.Domain.养殖基本信息表;
using Traceability.App.Domain.屠宰信息表;
using Traceability.App.ErrorCode;
using Traceability.App.Intrastructure.Interface;

namespace Traceability.App.Api.Read.Application.Handler.Kill
{
    public class KillGetHandler : IRequestHandler<KillGetCommand, ApiResult<KillInformationModel>>
    {
        private readonly IBaseRepository<KillInformationModel> KillRepo;
        private readonly IMapper mapper;

        public KillGetHandler(IBaseRepository<KillInformationModel> KillRepo, IMapper mapper)
        {
            this.KillRepo = KillRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<KillInformationModel>> Handle(KillGetCommand request, CancellationToken cancellationToken)
        {
            var res = new ApiResult<KillInformationModel>();
            var m = KillRepo.GetAll().Where(x => x.ProduceBatch == request.ProduceBatch).FirstOrDefault();
            res.Message = "养殖显示成功";
            res.Code = ApiEnum.Ok;
            res.Data = m;
            return Task.FromResult(res);
        }
    }
}
